﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoClassLibrary.BusinessLogicLayer;

public partial class Manager_SearchCourse : AdminUserBase
{
    public int trainingClassId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["trianClassId"] != null)
        {
            trainingClassId = int.Parse(Request.QueryString["trianClassId"]);
        }
        if (!this.IsPostBack)
        {

            bindPageData();
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        CourseModule cm = new CourseModule();
        string whereSql = " and vc_name like '%" + txtCourseName.Text.Trim() + "%'";
        DataSet ds = cm.GetCourseListByWhere(this.SchoolID, whereSql);
        repCourseList.DataSource = ds;
        repCourseList.DataBind();
    }
    protected void pager_PageChanged(object sender, EventArgs e)
    {
        bindPageData();
    }

    private void bindPageData()
    {
        int schoolId = this.CurrentUser.SchoolID;
        CourseModule cm = new CourseModule();
        DataSet ds = cm.QueryAllCourse(schoolId, " and trainClassID=" + trainingClassId);
        repCourseList.DataSource = this.getPage(ds);
        repCourseList.DataBind();
    }

    public PagedDataSource getPage(DataSet ds)
    {
        this.pager.RecordCount = ds.Tables[0].Rows.Count;
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = pager.CurrentPageIndex - 1;
        pds.PageSize = pager.PageSize;
        return pds;
    }
}
